Skip to content

fix(idempotency): treat empty or unparsable POWERTOOLS_IDEMPOTENCY_DISABLED as not disabled - #8734

Merged
leandrodamascena merged 5 commits into
aws-powertools:developfrom
lechakrawarthy:fix/idempotency-disabled-env
Nov 15, 2026
Merged

leandrodamascena merged 5 commits into
aws-powertools:developfrom
lechakrawarthy:fix/idempotency-disabled-env

Conversation

@lechakrawarthy

Copy link
Copy Markdown
Contributor

Issue number:

closes #8728

Summary

Changes

idempotent and idempotent_function both called strtobool(os.getenv("POWERTOOLS_IDEMPOTENCY_DISABLED", "false")), and strtobool raises ValueError for an empty string or any non-boolean value, so every invocation crashed before the handler ran.

  • Added _is_idempotency_disabled() in idempotency.py. It resolves the variable once and returns False for values strtobool rejects, with a debug log saying the value was ignored. Recognised values behave exactly as before.
  • Both decorators now use the helper.
  • I did not use resolve_truthy_env_var_choice from shared/functions.py: it calls the same strtobool and raises the same way, and changing it would change behaviour for every utility that uses it.

Tests

Added test_idempotency_disabled_envvar_empty_or_unparsable in tests/functional/idempotency/_boto3/test_idempotency.py, next to the existing env var tests. It runs both decorators with "", " ", "maybe" and the variable unset, and checks the functions return their result and the persistence layer is still called (idempotency stays on). The existing truthy and falsy cases are unchanged and still pass.

Verification

Ran locally on Windows (uv sync --locked --extra all --extra redis --extra datamasking; the valkey extra does not build on Windows).

New test on develop, before the fix:

FAILED ...::test_idempotency_disabled_envvar_empty_or_unparsable[]
FAILED ...::test_idempotency_disabled_envvar_empty_or_unparsable[ ]
FAILED ...::test_idempotency_disabled_envvar_empty_or_unparsable[maybe]
E       ValueError: invalid truth value 'maybe'
=========== 3 failed, 1 passed, 114 deselected, 1 warning in 15.51s ===========

With the fix:

uv run pytest tests/unit/idempotency tests/functional/idempotency -q
================ 206 passed, 88 warnings in 377.74s (0:06:17) =================

uv run mypy aws_lambda_powertools/utilities/idempotency/idempotency.py
Success: no issues found in 1 source file

After that run I split the debug log string over two lines (ruff E501) and re-ran the env var tests, ruff and mypy:

uv run pytest tests/functional/idempotency/_boto3/test_idempotency.py -q -k disabled
============== 11 passed, 107 deselected, 10 warnings in 31.08s ===============

uv run ruff format --check <changed files>
2 files already formatted

uv run ruff check <changed files>
All checks passed!

uv run mypy aws_lambda_powertools/utilities/idempotency/idempotency.py
Success: no issues found in 1 source file

AI disclosure

This change was made with the help of an AI coding assistant. I ran the commands above and the output is pasted as seen.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@lechakrawarthy
lechakrawarthy requested a review from a team as a code owner November 1, 2026 10:16
@boring-cyborg boring-cyborg Bot added the tests label Nov 1, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 1, 2026
…SABLED as not disabled

strtobool("") raised ValueError, so an empty or non-boolean value crashed
every invocation before the handler ran. Resolve the variable once in a
helper that returns False (with a debug log) for values strtobool rejects,
and use it in both idempotent and idempotent_function.
@lechakrawarthy
lechakrawarthy force-pushed the fix/idempotency-disabled-env branch from 308f637 to 364b675 Compare November 1, 2026 10:27
@leandrodamascena leandrodamascena added this to the 3.41.0 milestone Nov 1, 2026
@leandrodamascena

Copy link
Copy Markdown
Contributor

Thanks for the PR and for filling in the verification section, that helps. Heads up that the review may take a few days: this goes into 3.41.0 and I review every PR against a real service before approving, one at a time. No need to rebase or ping in the meantime, I'll come back here.

@leandrodamascena

Copy link
Copy Markdown
Contributor

Thanks @lechakrawarthy, and sorry for the detour. Your fix was right; what changed in the meantime is that #8783 landed a shared resolve_bool_env_var for this whole family of env vars, so I switched the two call sites to it instead of keeping a local helper, and made your test check the PowertoolsUserWarning it emits. Net change is three lines of code plus your test. I pushed it to your branch rather than asking you to redo it. Goes out in 3.41.0, you'll be in the release notes.

leandrodamascena added a commit that referenced this pull request Nov 14, 2026
…ad of crashing (#8757)

An empty or non-integer POWERTOOLS_PARAMETERS_MAX_AGE crashed every
parameters, secrets and AppConfig lookup with a raw ValueError from
int() before any AWS call was made (13 call sites share one resolver).

Resolve the variable through a helper that falls back to the documented
default with a PowertoolsUserWarning naming the ignored value (ADR 0006:
warn now, harden in a future major), mirroring the #8734 approach for
POWERTOOLS_IDEMPOTENCY_DISABLED. Recognized integer values, including 0
(no caching), behave exactly as before.

Regression test fails on develop with the ValueError and passes with the
fix for both malformed values.

Co-authored-by: Ayush Kumar Saha <225407166+AP24110011695@users.noreply.github.com>
Co-authored-by: Leandro Damascena <lcdama@amazon.pt>

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with the shared resolver in place, see my comment above. Thanks again @lechakrawarthy.

# Conflicts:
#	aws_lambda_powertools/utilities/idempotency/idempotency.py

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving after merging develop into the branch to clear a conflict in the imports; no functional change.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.17%. Comparing base (ff823e7) to head (f91076e).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8734      +/-   ##
===========================================
- Coverage    97.17%   97.17%   -0.01%     
===========================================
  Files          323      323              
  Lines        16629    16628       -1     
  Branches      1509     1509              
===========================================
- Hits         16160    16159       -1     
  Misses         328      328              
  Partials       141      141              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena
leandrodamascena merged commit 0637145 into aws-powertools:develop Nov 15, 2026
14 checks passed
@boring-cyborg

boring-cyborg Bot commented Nov 15, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@powertools-for-aws-oss-automation

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocation

2 participants